home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 December / DPPCPRO1205.ISO / Essentials / Programming / Basic4GL / Setup Basic4GL v2.3.1.exe / $INSTDIR / Programs / nehe16.gb < prev    next >
Encoding:
Text File  |  2005-07-29  |  7.4 KB  |  158 lines

  1.     dim light                       ' Lighting ON / OFF
  2.     dim xrot#                       ' X Rotation
  3.     dim yrot#                       ' Y Rotation
  4.     dim xspeed#                     ' X Rotation Speed
  5.     dim yspeed#                     ' Y Rotation Speed
  6.     dim z#                          ' Depth Into The Screen    
  7.     z# = -5
  8.     dim LightAmbient# (3)           ' Ambient Light Values
  9.     LightAmbient# = Vec4 (.5, .5, .5, 1)
  10.     dim LightDiffuse# (3)           ' Diffuse Light Values 
  11.     LightDiffuse# = Vec4 (1, 1, 1, 1)
  12.     dim LightPosition# (3)          ' Light Position
  13.     LightPosition# = Vec4 (0, 0, 2, 1)
  14.     dim filter                      ' Which Filter To Use
  15.     dim fogMode(2)
  16.     fogMode (0) = GL_EXP
  17.     fogMode (1) = GL_EXP2
  18.     fogMode (2) = GL_LINEAR         ' Storage For Three Types Of Fog
  19.     dim fogfilter                   ' Which Fog To Use
  20.     fogfilter = 0
  21.     dim fogColor#(3)                ' Fog Color
  22.     fogColor# = vec4(0.5, 0.5, 0.5, 1.0)     
  23.     dim texture(2)                  ' Storage for 3 textures
  24.     dim image
  25.     dim a$
  26.  
  27.     ' Load textures
  28.  
  29.     glGenTextures (3, texture)                      ' Generate 3 textures
  30.     dim i
  31.  
  32.     image = LoadImage ("Data/Crate.bmp")            ' Load crate image
  33.  
  34.     glBindTexture (GL_TEXTURE_2D, texture (0))
  35.     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
  36.     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
  37.     glTexImage2D (GL_TEXTURE_2D, 0, 3, ImageWidth(image), ImageHeight(image), 0, ImageFormat(image), ImageDataType(image), image)
  38.     
  39.     glBindTexture (GL_TEXTURE_2D, texture (1))
  40.     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
  41.     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
  42.     glTexImage2D (GL_TEXTURE_2D, 0, 3, ImageWidth(image), ImageHeight(image), 0, ImageFormat(image), ImageDataType(image), image)
  43.     
  44.     glBindTexture (GL_TEXTURE_2D, texture (2))
  45.     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
  46.     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST)
  47.     gluBuild2DMipmaps (GL_TEXTURE_2D, 3, ImageWidth(image), ImageHeight(image), ImageFormat(image), ImageDataType(image), image)
  48.  
  49.     DeleteImage (image)
  50.     
  51.     ' Init OpenGL
  52.     
  53.     glEnable(GL_TEXTURE_2D)                             ' Enable Texture Mapping
  54.     glShadeModel(GL_SMOOTH)                             ' Enable Smooth Shading
  55.     glClearColor(0.5,0.5,0.5,1.0)                       ' We'll Clear To The Color Of The Fog ( Modified )
  56.  
  57.     glFogi(GL_FOG_MODE, fogMode(fogfilter))             ' Fog Mode
  58.     glFogfv(GL_FOG_COLOR, fogColor#)                    ' Set Fog Color
  59.     glFogf(GL_FOG_DENSITY, 0.35)                        ' How Dense Will The Fog Be
  60.     glHint(GL_FOG_HINT, GL_DONT_CARE)                   ' Fog Hint Value
  61.     glFogf(GL_FOG_START, 1.0)                           ' Fog Start Depth
  62.     glFogf(GL_FOG_END, 5.0)                             ' Fog End Depth
  63.     glEnable(GL_FOG)                                    ' Enables GL_FOG
  64.  
  65.     glClearDepth(1.0)                                   ' Depth Buffer Setup
  66.     glEnable(GL_DEPTH_TEST)                             ' Enables Depth Testing
  67.     glDepthFunc(GL_LEQUAL)                              ' The Type Of Depth Testing To Do
  68.     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)   ' Really Nice Perspective Calculations
  69.  
  70.     glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient#)     ' Setup The Ambient Light
  71.     glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse#)     ' Setup The Diffuse Light
  72.     glLightfv(GL_LIGHT1, GL_POSITION,LightPosition#)    ' Position The Light
  73.     glEnable(GL_LIGHT1)                                 ' Enable Light One
  74.  
  75.     ' Main loop
  76.     while true
  77.         
  78.         ' Draw scene        
  79.         glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)    ' Clear The Screen And The Depth Buffer
  80.         glLoadIdentity ()                                       ' Reset The View       
  81.         glTranslatef (0.0,0.0,z#)
  82.     
  83.         glRotatef(xrot#,1.0,0.0,0.0)
  84.         glRotatef(yrot#,0.0,1.0,0.0)
  85.     
  86.         glBindTexture(GL_TEXTURE_2D, texture (filter))
  87.     
  88.         glBegin(GL_QUADS)
  89.             ' Front Face
  90.             glNormal3f( 0.0, 0.0, 1.0)
  91.             glTexCoord2f(0.0, 0.0): glVertex3f(-1.0, -1.0,  1.0)
  92.             glTexCoord2f(1.0, 0.0): glVertex3f( 1.0, -1.0,  1.0)
  93.             glTexCoord2f(1.0, 1.0): glVertex3f( 1.0,  1.0,  1.0)
  94.             glTexCoord2f(0.0, 1.0): glVertex3f(-1.0,  1.0,  1.0)
  95.             ' Back Face
  96.             glNormal3f( 0.0, 0.0,-1.0)
  97.             glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0, -1.0)
  98.             glTexCoord2f(1.0, 1.0): glVertex3f(-1.0,  1.0, -1.0)
  99.             glTexCoord2f(0.0, 1.0): glVertex3f( 1.0,  1.0, -1.0)
  100.             glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0, -1.0)
  101.             ' Top Face
  102.             glNormal3f( 0.0, 1.0, 0.0)
  103.             glTexCoord2f(0.0, 1.0): glVertex3f(-1.0,  1.0, -1.0)
  104.             glTexCoord2f(0.0, 0.0): glVertex3f(-1.0,  1.0,  1.0)
  105.             glTexCoord2f(1.0, 0.0): glVertex3f( 1.0,  1.0,  1.0)
  106.             glTexCoord2f(1.0, 1.0): glVertex3f( 1.0,  1.0, -1.0)
  107.             ' Bottom Face
  108.             glNormal3f( 0.0,-1.0, 0.0)
  109.             glTexCoord2f(1.0, 1.0): glVertex3f(-1.0, -1.0, -1.0)
  110.             glTexCoord2f(0.0, 1.0): glVertex3f( 1.0, -1.0, -1.0)
  111.             glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0,  1.0)
  112.             glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0,  1.0)
  113.             ' Right face
  114.             glNormal3f( 1.0, 0.0, 0.0)
  115.             glTexCoord2f(1.0, 0.0): glVertex3f( 1.0, -1.0, -1.0)
  116.             glTexCoord2f(1.0, 1.0): glVertex3f( 1.0,  1.0, -1.0)
  117.             glTexCoord2f(0.0, 1.0): glVertex3f( 1.0,  1.0,  1.0)
  118.             glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0,  1.0)
  119.             ' Left Face
  120.             glNormal3f(-1.0, 0.0, 0.0)
  121.             glTexCoord2f(0.0, 0.0): glVertex3f(-1.0, -1.0, -1.0)
  122.             glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0,  1.0)
  123.             glTexCoord2f(1.0, 1.0): glVertex3f(-1.0,  1.0,  1.0)
  124.             glTexCoord2f(0.0, 1.0): glVertex3f(-1.0,  1.0, -1.0)
  125.         glEnd()    
  126.         xrot# = xrot# + xspeed#
  127.         yrot# = yrot# + yspeed#
  128.         SwapBuffers ()
  129.         
  130.         a$ = inkey$()
  131.         if a$ = "L" or a$ = "l" then
  132.             light = not light
  133.             if not light then
  134.                 glDisable (GL_LIGHTING)
  135.             else
  136.                 glEnable (GL_LIGHTING)
  137.             endif
  138.         endif
  139.         if a$ = "F" or a$ = "f" then
  140.             filter = filter + 1
  141.             if filter > 2 then
  142.                 filter = 0
  143.             endif
  144.         endif      
  145.         if a$ = "G" or a$ = "g" then
  146.             fogfilter = fogfilter + 1
  147.             if fogfilter > 2 then 
  148.                 fogfilter = 0
  149.             endif
  150.             glFogi (GL_FOG_MODE, fogMode (fogfilter))
  151.         endif
  152.         if ScanKeyDown (VK_PRIOR)   then    z# = z# - 0.2               endif
  153.         if ScanKeyDown (VK_NEXT)    then    z# = z# + 0.2               endif
  154.         if ScanKeyDown (VK_UP)      then    xspeed# = xspeed# - 0.01    endif
  155.         if ScanKeyDown (VK_DOWN)    then    xspeed# = xspeed# + 0.01    endif
  156.         if ScanKeyDown (VK_RIGHT)   then    yspeed# = yspeed# + 0.01    endif
  157.         if ScanKeyDown (VK_LEFT)    then    yspeed# = yspeed# - 0.01    endif        
  158.     wend